home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Toolbox
/
Visual Basic Toolbox (P.I.E.)(1996).ISO
/
graphics
/
move4
/
move.frm
< prev
next >
Wrap
Text File
|
1995-10-22
|
12KB
|
365 lines
VERSION 4.00
Begin VB.Form WinStyles
Appearance = 0 'Flat
BackColor = &H00C0C0C0&
Caption = "Windows Style Manipulations"
ClientHeight = 6630
ClientLeft = 1005
ClientTop = 1545
ClientWidth = 7365
BeginProperty Font
name = "MS Sans Serif"
charset = 1
weight = 700
size = 8.25
underline = 0 'False
italic = 0 'False
strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 7035
Icon = "MOVE.frx":0000
Left = 945
LinkTopic = "Form1"
ScaleHeight = 6630
ScaleWidth = 7365
Top = 1200
Width = 7485
Begin VB.PictureBox Picture3
Appearance = 0 'Flat
BackColor = &H0000FFFF&
ForeColor = &H80000008&
Height = 855
Left = 480
ScaleHeight = 825
ScaleWidth = 2805
TabIndex = 6
Top = 5580
Width = 2835
End
Begin VB.PictureBox Picture2
Appearance = 0 'Flat
AutoRedraw = -1 'True
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 855
Left = 3960
ScaleHeight = 825
ScaleWidth = 2865
TabIndex = 5
Top = 5580
Width = 2895
End
Begin VB.TextBox Text2
Appearance = 0 'Flat
Height = 975
Left = 3960
TabIndex = 4
Text = "Text2"
Top = 4500
Width = 2895
End
Begin VB.CommandButton Command1
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "Push me !"
Height = 975
Left = 480
TabIndex = 3
Top = 4500
Width = 2835
End
Begin VB.TextBox Text1
Appearance = 0 'Flat
Height = 975
Left = 480
TabIndex = 2
Text = "Text1"
Top = 3300
Width = 6375
End
Begin VB.ListBox List1
Appearance = 0 'Flat
Height = 2760
Left = 3960
TabIndex = 1
Top = 360
Width = 2895
End
Begin VB.PictureBox Picture1
Appearance = 0 'Flat
AutoRedraw = -1 'True
BackColor = &H80000005&
BeginProperty Font
name = "MS Sans Serif"
charset = 1
weight = 400
size = 8.25
underline = 0 'False
italic = 0 'False
strikethrough = 0 'False
EndProperty
ForeColor = &H000000FF&
Height = 2775
Left = 480
Picture = "MOVE.frx":030A
ScaleHeight = 2745
ScaleWidth = 2865
TabIndex = 0
Top = 360
Width = 2895
End
End
Attribute VB_Name = "WinStyles"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
' * You nneed the MOVE.BAS as well ! *
Option Explicit
Dim retInt%, retLng&
Dim oldX%, oldY%
Private Sub Command1_Click()
MsgBox "If you hold down Ctrl you can even move me !", 64, "Notice"
End Sub
Private Sub Command1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
' --> from VB3 used the Mouse_Move event !
' this pice of code enables ANY concerned control to be moved freely --> even an entire form !
ReleaseCapture
retInt = SendMessage(Command1.hWnd, WM_SYSCOMMAND, MOUSE_MOVE, 0&)
End Sub
Private Sub Command1_KeyDown(KeyCode As Integer, Shift As Integer)
' can be move when Ctrl in pressed !
If Shift = 2 Then Command1.DragMode = 1
End Sub
Private Sub Command1_KeyUp(KeyCode As Integer, Shift As Integer)
Command1.DragMode = 0
End Sub
Private Sub Form_Load()
SetControls
Show
' after the form built we can insert a text now...
SetTexts
' (BUT: it it will only be shown until... (!?) - Well!
End Sub
Private Sub List1_Click()
List1.Clear
For retInt = 1 To 20
List1.AddItem "Item #" & retInt
Next retInt
End Sub
Private Sub List1_GotFocus()
ShowFocus List1
End Sub
Private Sub List1_LostFocus()
ShowFocus List1
End Sub
Private Sub Picture1_GotFocus()
ShowFocus Picture1
End Sub
Private Sub Picture1_LostFocus()
ShowFocus Picture1
End Sub
Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
' this should only be possible for the LEFT mouse key as usual.
If Button <> 1 Then Exit Sub
' this pice of code enables ANY concerned control to be moved freely --> even an entire form !
ReleaseCapture
retInt = SendMessage(Picture2.hWnd, WM_SYSCOMMAND, MOUSE_MOVE, 0&)
End Sub
Private Sub Picture3_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub
Picture3.ZOrder
oldX = X
oldY = Y
End Sub
Private Sub Picture3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub
Picture3.Left = Picture3.Left + X - oldX
Picture3.TOP = Picture3.TOP + Y - oldY
End Sub
' '
' Here, all the setting are done. '
' *** WARNING *** '
' This code was just put together for a demonstration. '
' (YES, it was tested. THIS code is OK.) '
' Please be careful with YOUR experiments !!! '
' Noone will be responsible for your "results" ! '
' BUT: good results should be given to the public ! '
' '
Private Sub SetControls()
Dim Style&
Style = GetWindowLong(Picture1.hWnd, GWL_STYLE) ' Obtain the actual style
Style = Style Or WS_THICKFRAME ' Give it a Sizable Frame
Style = Style Or WS_CAPTION ' Give it a Caption
Style = Style Or WS_MINIMIZEBOX ' Give it a MinimizeBox
Style = Style Or WS_SYSMENU ' Give it a System Menu
Style = SetWindowLong(Picture1.hWnd, GWL_STYLE, Style) ' - pass the new style
Picture1.Height = Picture1.Height ' ! REBUILD THE CONTROL !
retInt = SetWindowText(Picture1.hWnd, "The Picture Box") ' Give it a Name, too
Picture1.Height = Picture1.Height + 30 ' ! REBUILD THE CONTROL !
Picture1.Height = Picture1.Height - 30 ' the "extra kick" for VB4
Picture1.CurrentY = 700
Picture1.ForeColor = &HFF0000 ' [blue]
Picture1.Print " This is a demonstration."
Picture1.ForeColor = &H0& ' [black]
Picture1.Print " Please";
Picture1.ForeColor = &HFF& ' [red]
Picture1.Print " do not add";
Picture1.ForeColor = &H0& ' [black]
Picture1.Print " system menus"
Picture1.Print " to controls like this here !"
Style = GetWindowLong(List1.hWnd, GWL_STYLE) ' Obtain the actual style
Style = Style Or WS_THICKFRAME ' Give it a Dizable Frame
Style = Style Or WS_CAPTION ' Give it a Caption
Style = Style Xor WS_MAXIMIZEBOX ' Remove the MaximizeBox
Style = SetWindowLong(List1.hWnd, GWL_STYLE, Style) ' - pass the new style
retInt = SetWindowText(List1.hWnd, "The List Box") ' Give it a Name
List1.Height = List1.Height + 30 ' ! REBUILD THE CONTROL !
List1.Height = List1.Height - 30 ' the "extra kick" for VB4
List1.AddItem "Its nice and easy"
List1.AddItem "to manipulate controls"
List1.AddItem "this way !!!"
List1.AddItem "Come on, try it yourself !"
Style = GetWindowLong(Text1.hWnd, GWL_STYLE) ' Obtain the actual style
Style = Style Or WS_BORDER ' Give it a Thin Frame (--> you may leave this out)
Style = Style Or WS_CAPTION ' Give it a Caption
Style = Style Xor WS_MAXIMIZEBOX ' Remove the MaximizeBox
Style = SetWindowLong(Text1.hWnd, GWL_STYLE, Style) ' - pass the new style
retInt = SetWindowText(Text1.hWnd, "The Text Box 1") ' Give it a Name
' same as: Text1 = "The Text Box"
' NOTE: you can alter the text later.
Text1.Height = Text1.Height + 30 ' ! REBUILD THE CONTROL !
Text1.Height = Text1.Height - 30 ' ! REBUILD THE CONTROL !
Style = GetWindowLong(Command1.hWnd, GWL_STYLE) ' Obtain the actual style
Style = Style Or WS_BORDER ' Give it a border (--> don't leave this out)
Style = Style Or WS_THICKFRAME ' Give it a sizable frame
Style = SetWindowLong(Command1.hWnd, GWL_STYLE, Style) ' - pass the new style
Command1.Height = Command1.Height ' ! REBUILD THE CONTROL !
Style = GetWindowLong(Text2.hWnd, GWL_STYLE) ' Obtain the actual style
Style = Style Or WS_CAPTION ' Give it a Caption
Style = Style Xor WS_MAXIMIZEBOX ' Remove the Maximizebox
Style = SetWindowLong(Text2.hWnd, GWL_STYLE, Style) ' - pass the new style
Style = GetWindowLong(Text2.hWnd, GWL_EXSTYLE) ' Obtain the actual extended style
Style = Style Or WS_EX_DLGMODALFRAME ' Give it a Thick Border
Style = SetWindowLong(Text2.hWnd, GWL_EXSTYLE, Style) ' - pass the new extended style
retInt = SetWindowText(Text2.hWnd, "The Text Box 2")
' same as: Text2 = "The Text Box"
Text2.Height = Text2.Height + 30 ' ! REBUILD THE CONTROL !
Text2.Height = Text2.Height - 30 ' the "extra kick" for VB4
Picture2.CurrentX = 270
Picture2.CurrentY = 180
Picture2.Print "Step on me and move me !"
Dim Text$
Text = "(Don't be shy)" ' center the text correctly
Picture2.CurrentX = (Picture2.ScaleWidth - Picture2.TextWidth(Text)) / 2
Picture2.ForeColor = &HFF0008 ' [= blue]
Picture2.Print Text
End Sub
Private Sub SetTexts()
Text1 = "Hi, I have no sizable border but a caption."
Text2 = "I have a fixed double border..."
End Sub
' '
' Well, we have to help VB a little... '
' '
Private Sub ShowFocus(Control As Control)
' switches the active view of the caption on (and off !)
' note: this a toggle function ; retInt receives the old value
retInt = FlashWindow(Control.hWnd, True)
End Sub
Private Sub Text1_GotFocus()
ShowFocus Text1
End Sub
Private Sub Text1_LostFocus()
ShowFocus Text1
End Sub
Private Sub Text2_GotFocus()
ShowFocus Text2
End Sub
Private Sub Text2_LostFocus()
ShowFocus Text2
End Sub